package edu.gyc.myshop.service.impl;

import edu.gyc.myshop.model.Cart;
import edu.gyc.myshop.model.Goods;
import edu.gyc.myshop.model.Myuser;
import edu.gyc.myshop.model.OrderDetail;
import edu.gyc.myshop.dao.OrderDetailDao;
import edu.gyc.myshop.service.GoodsService;
import edu.gyc.myshop.service.OrderDetailService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.servlet.http.HttpSession;
import java.util.List;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author ls
 * @since 2024-04-19
 */
@Service
public class OrderDetailServiceImpl extends ServiceImpl<OrderDetailDao, OrderDetail> implements OrderDetailService {

    @Autowired
    GoodsService goodsService;
    @Override
    public List<OrderDetail> listOrderDeatailById(int orderId) {
            List<OrderDetail> orderDetails = this.lambdaQuery()
                    .eq(OrderDetail::getOrderid, orderId)

                    .list();
            if (orderDetails.size() > 0) {
                for (int i = 0; i < orderDetails.size(); i++) {
                    OrderDetail orderDetail = orderDetails.get(i);
                    Goods goods = goodsService.lambdaQuery()
                            .eq(Goods::getId, orderDetail.getGoodsid()).one();
                    orderDetail.setPriceSum(orderDetail.getBuyNum()*orderDetail.getPrice() );
                    orderDetail.setGoodsPic(goods.getPicture());
                    orderDetail.setGoodsPrice(goods.getPrice());
                    orderDetail.setGoodsName(goods.getName());
                }
                return orderDetails;
            }
        return null;
    }
}
